package com.hjl.service.provider;

import com.hjl.dao.provider.ProviderMapper;
import com.hjl.entity.Provider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("providerService")
public class ProviderServiceImpl implements ProviderService {

    @Autowired
    private ProviderMapper providerMapper;

/*    public ProviderMapper getProviderMapper() {
        return providerMapper;
    }

    public void setProviderMapper(ProviderMapper providerMapper) {
        this.providerMapper = providerMapper;
    }*/

    @Override
    public List<Provider> getListInfos(String proName) {

        try {
            return providerMapper.getListInfo(proName);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public boolean addNewProvider(Provider provider) {

        boolean result = false;

        try {
            if (providerMapper.add(provider) == 1) {
                result = true;
            }
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
        return result;
    }

    @Override
    public int modifyProvider(Provider provider) {
        int count = 0;
        try {
            count = providerMapper.updateInfos(provider);
            // 模拟异常，进行回滚
            //int i = 1/0;
            return count;
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public int deleteInfos(int id) {

        int count = -1;

        try {
            count = providerMapper.delete(id);
            // 模拟异常，进行回滚
            //int i = 1/0;
            return count;
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

}
